﻿namespace IPMS.BLL
{
    using IPMS.DAL;
    using System;
    using System.Data;
    using System.Data.SqlClient;

    public class ProjectHeading
    {
        private DateTime _ACMEDueDate;
        private bool _Action;
        private DateTime _AgentDueDate;
        private DateTime _CompletionDate;
        private string _CreateBy;
        private DateTime _DateFld1;
        private DateTime _DateFld2;
        private DateTime _DateFld3;
        private DateTime _DateFld4;
        private DateTime _DateFld5;
        private decimal _DeciFld1;
        private decimal _DeciFld2;
        private string _DocumentNumber;
        private bool _FromTemplateYN;
        private string _HeadingCode;
        private string _HeadingSet;
        private bool _IsLastProgress;
        private string _OwnerGroupID;
        private string _ProjectCode;
        private string _Remark;
        private string _Remark1;
        private string _Remark2;
        private string _Remark3;
        private string _Remark4;
        private string _Remark5;
        private string _ResponsibleBy;
        private string _Section;
        private string _Sequence;
        private string _Status;
        private string _UpdateBy;

        public ProjectHeading(string projectCode, string headingSet, string headingCode, string status, string createBy, string updateBy, string ownergroupID)
        {
            this._ProjectCode = projectCode;
            this._HeadingSet = headingSet;
            this._HeadingCode = headingCode;
            this._Status = status;
            this._CreateBy = createBy;
            this._UpdateBy = updateBy;
            this._OwnerGroupID = ownergroupID;
        }

        public int GetProjectHeaderInfo(string rowpointer)
        {
            SqlCommand sqlCmd = new SqlCommand();
            DataAccessLayer DAL = new DataAccessLayer();
            DAL.AddParamToSQLCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@RowPointer", SqlDbType.NVarChar, 0xff, ParameterDirection.Input, rowpointer.ToString());
            DAL.AddParamToSQLCmd(sqlCmd, "@ProjectCode", SqlDbType.NVarChar, 30, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@HeadingCode", SqlDbType.NVarChar, 30, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@HeadingName", SqlDbType.NVarChar, 100, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@Section", SqlDbType.NVarChar, 30, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@Action", SqlDbType.Bit, 1, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@DocumentNumber", SqlDbType.NVarChar, 30, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@Status", SqlDbType.NVarChar, 30, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@Remark", SqlDbType.NVarChar, 100, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@ACMEDueDate", SqlDbType.DateTime, 8, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@AgentDueDate", SqlDbType.DateTime, 8, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@CompletionDate", SqlDbType.DateTime, 8, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@ResponsibleBy", SqlDbType.NVarChar, 30, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@Remark1", SqlDbType.NVarChar, 100, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@Remark2", SqlDbType.NVarChar, 100, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@Remark3", SqlDbType.NVarChar, 100, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@Remark4", SqlDbType.NVarChar, 100, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@Remark5", SqlDbType.NVarChar, 100, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@DateFld1", SqlDbType.DateTime, 8, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@DateFld2", SqlDbType.DateTime, 8, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@DateFld3", SqlDbType.DateTime, 8, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@DateFld4", SqlDbType.DateTime, 8, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@DateFld5", SqlDbType.DateTime, 8, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@DeciFld1", SqlDbType.Decimal, 13, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@DeciFld2", SqlDbType.Decimal, 13, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@FromTemplateYN", SqlDbType.Bit, 1, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@IsLastProgress", SqlDbType.Bit, 1, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@Sequence", SqlDbType.Int, 0, ParameterDirection.Output, null);
            DAL.SetCommandType(sqlCmd, CommandType.StoredProcedure, "RetrieveProjectHeadingSp");
            DAL.ExecuteScalarCmd(sqlCmd);
            int resultValue = Convert.ToInt16(sqlCmd.Parameters["@ReturnValue"].Value);
            this._ProjectCode = (string) sqlCmd.Parameters["@ProjectCode"].Value;
            this._HeadingCode = (string) sqlCmd.Parameters["@HeadingCode"].Value;
            this._HeadingSet = (string) sqlCmd.Parameters["@HeadingName"].Value;
            this._Section = (string) sqlCmd.Parameters["@Section"].Value;
            this._Action = (bool) sqlCmd.Parameters["@Action"].Value;
            this._DocumentNumber = (string) sqlCmd.Parameters["@DocumentNumber"].Value;
            this._Status = (string) sqlCmd.Parameters["@Status"].Value;
            this._Remark = (string) sqlCmd.Parameters["@Remark"].Value;
            this._ACMEDueDate = (DateTime) sqlCmd.Parameters["@ACMEDueDate"].Value;
            this._AgentDueDate = (DateTime) sqlCmd.Parameters["@AgentDueDate"].Value;
            this._CompletionDate = (DateTime) sqlCmd.Parameters["@CompletionDate"].Value;
            this._ResponsibleBy = (string) sqlCmd.Parameters["@ResponsibleBy"].Value;
            this._Remark1 = (string) sqlCmd.Parameters["@Remark1"].Value;
            this._Remark2 = (string) sqlCmd.Parameters["@Remark2"].Value;
            this._Remark3 = (string) sqlCmd.Parameters["@Remark3"].Value;
            this._Remark4 = (string) sqlCmd.Parameters["@Remark4"].Value;
            this._Remark5 = (string) sqlCmd.Parameters["@Remark5"].Value;
            this._DateFld1 = (DateTime) sqlCmd.Parameters["@DateFld1"].Value;
            this._DateFld2 = (DateTime) sqlCmd.Parameters["@DateFld2"].Value;
            this._DateFld3 = (DateTime) sqlCmd.Parameters["@DateFld3"].Value;
            this._DateFld4 = (DateTime) sqlCmd.Parameters["@DateFld4"].Value;
            this._DateFld5 = (DateTime) sqlCmd.Parameters["@DateFld5"].Value;
            this._DeciFld1 = (decimal) sqlCmd.Parameters["@DeciFld1"].Value;
            this._DeciFld2 = (decimal) sqlCmd.Parameters["@DeciFld2"].Value;
            this._FromTemplateYN = (bool) sqlCmd.Parameters["@FromTemplateYN"].Value;
            this._IsLastProgress = (bool) sqlCmd.Parameters["@IsLastProgress"].Value;
            this._Sequence = Convert.ToString(sqlCmd.Parameters["@Sequence"].Value);
            return resultValue;
        }

        public int InsertProjectHeaderByHeadingSet()
        {
            SqlCommand sqlCmd = new SqlCommand();
            DataAccessLayer DAL = new DataAccessLayer();
            DAL.AddParamToSQLCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@HeadingSet", SqlDbType.NVarChar, 0xff, ParameterDirection.Input, this._HeadingSet.ToString());
            DAL.AddParamToSQLCmd(sqlCmd, "@ProjectCode", SqlDbType.NVarChar, 0xff, ParameterDirection.Input, this._ProjectCode.ToString());
            DAL.AddParamToSQLCmd(sqlCmd, "@Status", SqlDbType.NVarChar, 0xff, ParameterDirection.Input, this._Status.ToString());
            DAL.AddParamToSQLCmd(sqlCmd, "@CreateBy", SqlDbType.NVarChar, 0xff, ParameterDirection.Input, this._CreateBy.ToString());
            DAL.AddParamToSQLCmd(sqlCmd, "@UpdateBy", SqlDbType.NVarChar, 0xff, ParameterDirection.Input, this._UpdateBy.ToString());
            DAL.AddParamToSQLCmd(sqlCmd, "@OwnerGroupID", SqlDbType.NVarChar, 0xff, ParameterDirection.Input, this._OwnerGroupID.ToString());
            DAL.SetCommandType(sqlCmd, CommandType.StoredProcedure, "SetProjectHeadingBulkSp");
            DAL.ExecuteScalarCmd(sqlCmd);
            return Convert.ToInt16(sqlCmd.Parameters["@ReturnValue"].Value);
        }

        public int InsertProjectHeaderByHeadingTemplate()
        {
            SqlCommand sqlCmd = new SqlCommand();
            DataAccessLayer DAL = new DataAccessLayer();
            DAL.AddParamToSQLCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@ProjectCode", SqlDbType.NVarChar, 0xff, ParameterDirection.Input, this._ProjectCode.ToString());
            DAL.AddParamToSQLCmd(sqlCmd, "@HeadingCode", SqlDbType.NVarChar, 0xff, ParameterDirection.Input, this._HeadingCode.ToString());
            DAL.AddParamToSQLCmd(sqlCmd, "@Status", SqlDbType.NVarChar, 0xff, ParameterDirection.Input, this._Status.ToString());
            DAL.AddParamToSQLCmd(sqlCmd, "@CreateBy", SqlDbType.NVarChar, 0xff, ParameterDirection.Input, this._CreateBy.ToString());
            DAL.AddParamToSQLCmd(sqlCmd, "@UpdateBy", SqlDbType.NVarChar, 0xff, ParameterDirection.Input, this._UpdateBy.ToString());
            DAL.AddParamToSQLCmd(sqlCmd, "@OwnerGroupID", SqlDbType.NVarChar, 0xff, ParameterDirection.Input, this._OwnerGroupID.ToString());
            DAL.SetCommandType(sqlCmd, CommandType.StoredProcedure, "SetProjectHeadingSp");
            DAL.ExecuteScalarCmd(sqlCmd);
            return Convert.ToInt16(sqlCmd.Parameters["@ReturnValue"].Value);
        }

        public bool Action
        {
            get
            {
                return this._Action;
            }
        }

        public DateTime AgentDueDate
        {
            get
            {
                return this._AgentDueDate;
            }
        }

        public DateTime CompanyDueDate
        {
            get
            {
                return this._ACMEDueDate;
            }
        }

        public DateTime CompletionDate
        {
            get
            {
                return this._CompletionDate;
            }
        }

        public string DocumentNumber
        {
            get
            {
                return this._DocumentNumber;
            }
        }

        public string HeadingCode
        {
            get
            {
                return this._HeadingCode;
            }
        }

        public string HeadingName
        {
            get
            {
                return this._HeadingSet;
            }
        }

        public string ProjectCode
        {
            get
            {
                return this._ProjectCode;
            }
        }

        public string Remarks
        {
            get
            {
                return this._Remark;
            }
        }

        public string Sequence
        {
            get
            {
                return this._Sequence;
            }
        }

        public string Status
        {
            get
            {
                return this._Status;
            }
        }
    }
}

